﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace RLZY.DAL
{
	/// <summary>
	/// 数据访问类:GGLSG_DD
	/// </summary>
	public partial class GGLSG_DD
	{
		public GGLSG_DD()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(RLZY.Model.GGLSG_DD model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into GGLSG_DD(");
			strSql.Append("日期,姓名,收入,合同类别,工作年,部门,身份证号码,合同备注,人数,月数,工龄,年月平均,时间,清理类别)");
			strSql.Append(" values (");
			strSql.Append("@日期,@姓名,@收入,@合同类别,@工作年,@部门,@身份证号码,@合同备注,@人数,@月数,@工龄,@年月平均,@时间,@清理类别)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@日期", SqlDbType.VarChar,20),
					new SqlParameter("@姓名", SqlDbType.VarChar,20),
					new SqlParameter("@收入", SqlDbType.Decimal,9),
					new SqlParameter("@合同类别", SqlDbType.VarChar,20),
					new SqlParameter("@工作年", SqlDbType.VarChar,4),
					new SqlParameter("@部门", SqlDbType.VarChar,30),
					new SqlParameter("@身份证号码", SqlDbType.VarChar,30),
					new SqlParameter("@合同备注", SqlDbType.VarChar,50),
					new SqlParameter("@人数", SqlDbType.Int,4),
					new SqlParameter("@月数", SqlDbType.Decimal,9),
					new SqlParameter("@工龄", SqlDbType.Decimal,9),
					new SqlParameter("@年月平均", SqlDbType.Decimal,9),
					new SqlParameter("@时间", SqlDbType.DateTime),
					new SqlParameter("@清理类别", SqlDbType.VarChar,20)};
			parameters[0].Value = model.日期;
			parameters[1].Value = model.姓名;
			parameters[2].Value = model.收入;
			parameters[3].Value = model.合同类别;
			parameters[4].Value = model.工作年;
			parameters[5].Value = model.部门;
			parameters[6].Value = model.身份证号码;
			parameters[7].Value = model.合同备注;
			parameters[8].Value = model.人数;
			parameters[9].Value = model.月数;
			parameters[10].Value = model.工龄;
			parameters[11].Value = model.年月平均;
			parameters[12].Value = model.时间;
			parameters[13].Value = model.清理类别;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(RLZY.Model.GGLSG_DD model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update GGLSG_DD set ");
			strSql.Append("日期=@日期,");
			strSql.Append("姓名=@姓名,");
			strSql.Append("收入=@收入,");
			strSql.Append("合同类别=@合同类别,");
			strSql.Append("工作年=@工作年,");
			strSql.Append("部门=@部门,");
			strSql.Append("身份证号码=@身份证号码,");
			strSql.Append("合同备注=@合同备注,");
			strSql.Append("人数=@人数,");
			strSql.Append("月数=@月数,");
			strSql.Append("工龄=@工龄,");
			strSql.Append("年月平均=@年月平均,");
			strSql.Append("时间=@时间,");
			strSql.Append("清理类别=@清理类别");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@日期", SqlDbType.VarChar,20),
					new SqlParameter("@姓名", SqlDbType.VarChar,20),
					new SqlParameter("@收入", SqlDbType.Decimal,9),
					new SqlParameter("@合同类别", SqlDbType.VarChar,20),
					new SqlParameter("@工作年", SqlDbType.VarChar,4),
					new SqlParameter("@部门", SqlDbType.VarChar,30),
					new SqlParameter("@身份证号码", SqlDbType.VarChar,30),
					new SqlParameter("@合同备注", SqlDbType.VarChar,50),
					new SqlParameter("@人数", SqlDbType.Int,4),
					new SqlParameter("@月数", SqlDbType.Decimal,9),
					new SqlParameter("@工龄", SqlDbType.Decimal,9),
					new SqlParameter("@年月平均", SqlDbType.Decimal,9),
					new SqlParameter("@时间", SqlDbType.DateTime),
					new SqlParameter("@清理类别", SqlDbType.VarChar,20),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = model.日期;
			parameters[1].Value = model.姓名;
			parameters[2].Value = model.收入;
			parameters[3].Value = model.合同类别;
			parameters[4].Value = model.工作年;
			parameters[5].Value = model.部门;
			parameters[6].Value = model.身份证号码;
			parameters[7].Value = model.合同备注;
			parameters[8].Value = model.人数;
			parameters[9].Value = model.月数;
			parameters[10].Value = model.工龄;
			parameters[11].Value = model.年月平均;
			parameters[12].Value = model.时间;
			parameters[13].Value = model.清理类别;
			parameters[14].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from GGLSG_DD ");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
			};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from GGLSG_DD ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RLZY.Model.GGLSG_DD GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,日期,姓名,收入,合同类别,工作年,部门,身份证号码,合同备注,人数,月数,工龄,年月平均,时间,清理类别 from GGLSG_DD ");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
			};
			parameters[0].Value = ID;

			RLZY.Model.GGLSG_DD model=new RLZY.Model.GGLSG_DD();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RLZY.Model.GGLSG_DD DataRowToModel(DataRow row)
		{
			RLZY.Model.GGLSG_DD model=new RLZY.Model.GGLSG_DD();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=int.Parse(row["ID"].ToString());
				}
				if(row["日期"]!=null)
				{
					model.日期=row["日期"].ToString();
				}
				if(row["姓名"]!=null)
				{
					model.姓名=row["姓名"].ToString();
				}
				if(row["收入"]!=null && row["收入"].ToString()!="")
				{
					model.收入=decimal.Parse(row["收入"].ToString());
				}
				if(row["合同类别"]!=null)
				{
					model.合同类别=row["合同类别"].ToString();
				}
				if(row["工作年"]!=null)
				{
					model.工作年=row["工作年"].ToString();
				}
				if(row["部门"]!=null)
				{
					model.部门=row["部门"].ToString();
				}
				if(row["身份证号码"]!=null)
				{
					model.身份证号码=row["身份证号码"].ToString();
				}
				if(row["合同备注"]!=null)
				{
					model.合同备注=row["合同备注"].ToString();
				}
				if(row["人数"]!=null && row["人数"].ToString()!="")
				{
					model.人数=int.Parse(row["人数"].ToString());
				}
				if(row["月数"]!=null && row["月数"].ToString()!="")
				{
					model.月数=decimal.Parse(row["月数"].ToString());
				}
				if(row["工龄"]!=null && row["工龄"].ToString()!="")
				{
					model.工龄=decimal.Parse(row["工龄"].ToString());
				}
				if(row["年月平均"]!=null && row["年月平均"].ToString()!="")
				{
					model.年月平均=decimal.Parse(row["年月平均"].ToString());
				}
				if(row["时间"]!=null && row["时间"].ToString()!="")
				{
					model.时间=DateTime.Parse(row["时间"].ToString());
				}
				if(row["清理类别"]!=null)
				{
					model.清理类别=row["清理类别"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,日期,姓名,收入,合同类别,工作年,部门,身份证号码,合同备注,人数,月数,工龄,年月平均,时间,清理类别 ");
			strSql.Append(" FROM GGLSG_DD ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,日期,姓名,收入,合同类别,工作年,部门,身份证号码,合同备注,人数,月数,工龄,年月平均,时间,清理类别 ");
			strSql.Append(" FROM GGLSG_DD ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM GGLSG_DD ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from GGLSG_DD T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "GGLSG_DD";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

